# -*- coding: utf-8 -*-




import uvicorn
from fastapi import FastAPI

from web.config.AuthMiddleware import AuthMiddleware
from web.config.Config import CONFIG
from web.config.Logger import logger

from web.tdx.sever.RealTimeQuotes import RealTimeQuotes

from web.controller.RealTimeController import testRouter
from web.controller.HistoryController import historyRouter


app = FastAPI()

async def startup_event():
    logger.info("FastAPI 应用正在初始化")
    RealTimeQuotes()
    logger.info("FastAPI 应用已启动")
    # 在这里执行启动时的初始化代码


async def shutdown_event():
    print("FastAPI 应用正在关闭")
    # 在这里执行关闭时的清理代码


app.add_event_handler("startup", startup_event)
app.add_event_handler("shutdown", shutdown_event)
app.add_middleware(AuthMiddleware)


app.include_router(testRouter, prefix="/realTime")
app.include_router(historyRouter, prefix="/history")


if __name__ == '__main__':
    uvicorn.run(
        app=app,
        host= CONFIG['server']['host'],
        port= CONFIG['server']['port']
    )


